

/**
 *@param {Array} position = [114.30,30.50]
 *@param {Array} attr = [{name:事件编号,type:"string",value: inputId}]
 *@param {Object} service = {name:"xm",layerId:2} 
 *@param {Object} docLayer = $docLayer
 *  
 * */
 export function addPoint({
    position,
    attr,
    service,
    docLayer
}) {
    /* new ol.geom.Point([118,30]) */
    var gpoint = new Zondy.Object.GPoint(position[0], position[1]);//createPoint();
    //设置当前点要素的几何信息
    var fGeom = new Zondy.Object.FeatureGeometry({ PntGeom: [gpoint] });
    
    // 根据事件状态设置点要素颜色
    let color ;
    console.log(attr.filter(item => item.name === "处理状态").map(item => item.value));
    if(attr.filter(item => item.name === "处理状态").map(item => item.value)==0){
        color = 6;
    }
    else if(attr.filter(item => item.name === "处理状态").map(item => item.value)==1){
        color = 4;
    }
    else if(attr.filter(item => item.name === "处理状态").map(item => item.value)==2){
        color = 90;
    };
    //描述点要素的符号参数信息
    var pointInfo = new Zondy.Object.CPointInfo({
        Angle: 0,
        Color: color,//子图颜色
        Space: 0,
        SymHeight: 5,//高度
        SymID: 21,//子图号
        SymWidth: 5//宽度
    });
    //设置当前点要素的图形参数信息
    var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({
        /* 1-Point  2-Line  3-Area */
        InfoType: 1,
        PntInfo: pointInfo
    });
    var attValue = attr.map(item => item.value)
    //创建一个要素
    var feature = new Zondy.Object.Feature({
        fGeom: fGeom,//几何信息
        GraphicInfo: webGraphicInfo,//图形信息
        AttValue: attValue//属性信息
    });
    //设置要素为点要素
    feature.setFType(1);//1 -point 2--line 3-area
    /* 2、创建数据源 */
    /* new ol.source.Vector({}) */
    var featureSet = new Zondy.Object.FeatureSet();
    //设置属性结构  数据源的属性结构和mapgis中的图层的字段映射
    var cAttStruct = new Zondy.Object.CAttStruct({
        FldName: attr.map(item => item.name),
        FldNumber: attr.length,
        FldType: attr.map(item => item.type), 
    });
    featureSet.AttStruct = cAttStruct;
    //添加要素到要素数据集
    featureSet.addFeature(feature);
    /* 3、调用服务向mapgis中的地图文档中的图层添加 */
    /* 地图文档的名称 Map
       添加要素所在的图层 Layer
     */
    /* http请求  post */
    var editService = new Zondy.Service.EditDocFeature(service.name, service.layerId, {
    });
    //执行添加点要素功能
    editService.add(featureSet, onPntSuccess(docLayer));
    

}

 function onPntSuccess(docLayer) {
     return function (data) {
        console.log(data);
        if (data.succeed) {
            alert("添加点要素成功！");
            console.log(docLayer);
            docLayer.refresh();
        } else {
            alert("添加点要素失败！");
        }
    }
}